package com.itany.corejava.code07_常用类.泛型;

/**
 * @author MissChen
 * @date 2024年03月02日 14:12
 */
public class Test01_泛型 {
    public static void main(String[] args) {
        // JDK7 之前定义方式: 类名<类型> 变量名 = new 类名<类型>()
        // JDK7 之后定义方式: 类名<类型> 变量名 = new 类名<>()

        Student<Integer> student=new Student<Integer>();
        // Student<Integer> student=new Student<>();
        student.setNo(10);
        System.out.println(student);

        Student<String> student2=new Student<>();
        student2.setNo("wbs111");
        System.out.println(student2);
        Stu stu=new Stu();
        //使用Object可以指定任意类型
        //缺乏类型安全，不建议使用
        stu.setNo(1);
        stu.setNo("wbs222");
        stu.setNo(student);


    }
}
class Student<T>{
    private T no;
    private String name;

    public Student() {
    }

    public Student(T no, String name) {
        this.no = no;
        this.name = name;
    }

    public T getNo() {
        return no;
    }

    public void setNo(T no) {
        this.no = no;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Student{" +
                "no=" + no +
                ", name='" + name + '\'' +
                '}';
    }
}
class Stu{
    private Object no;

    public Object getNo() {
        return no;
    }

    public void setNo(Object no) {
        this.no = no;
    }

    @Override
    public String toString() {
        return "Stu{" +
                "no=" + no +
                '}';
    }
}